package cn.rtplay.esp32camcar.rxHttpGet.observers;

import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ProgressBar;

import cn.rtplay.esp32camcar.toolUtils.LogUtil;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;

/**
 * Created by JohnsonFan on 2017/9/29.
 */

public abstract class ProgressObserver<T> extends  BaseObserver<T>{
	//private MaterialDialog mMaterialDialog;
	private final Activity mContext;
    private ProgressBar mProgressBar;

	public ProgressObserver(Activity context){
		mContext = context;
	}

	@Override
	public void onSubscribe(@NonNull Disposable d) {
		if (!d.isDisposed()) {
            mProgressBar = new ProgressBar(mContext);
			FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
			params.gravity = Gravity.CENTER;
			mContext.addContentView(mProgressBar,params);
		}
	}

	@Override
	public void onComplete() {
		LogUtil.e("ProgressObserver", "onComplete: in" );
		mProgressBar.setVisibility(View.INVISIBLE);
		mProgressBar = null;
	}

	@Override
	public void onError(@NonNull Throwable e) {
		super.onError(e);
		mProgressBar.setVisibility(View.INVISIBLE);
		mProgressBar = null;
	}

}
